package program

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/v2/assignments/\\d+/quizzes/\\d+/excellentQuizzes')),
                producer('/api/v2/assignments/1/quizzes/1/excellentQuizzes'))
        headers {
            contentType(applicationJsonUtf8())
        }
    }
    response {
        status(200)
        headers {
            contentType(applicationJsonUtf8())
        }
        body("""
        [{
            "id" : 3,
            "studentId" : 21,
            "quizId" : 1,
            "assignmentId" : 1,
            "status" : "优秀",
            "createTime" : "2018-09-26 03:05:45.0",
            "userName" : "张三"
        }]
        """)

        bodyMatchers {
            jsonPath('$.[*]', byType())
            jsonPath('$.[*].id', byRegex(number()))
            jsonPath('$.[*].studentId', byRegex(number()))
            jsonPath('$.[*].quizId', byRegex(number()))
            jsonPath('$.[*].assignmentId', byRegex(number()))
            jsonPath('$.[*].status', byRegex(nonEmpty()))
            jsonPath('$.[*].createTime', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].userName', byRegex(nonEmpty()))
        }
    }

}